<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="父订单号" prop="partnerOrderNo">
        <el-input
          v-model="queryParams.partnerOrderNo"
          placeholder="请输入父订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单编号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="技师" prop="tid">
        <el-input
          v-model="queryParams.tid"
          placeholder="请输入技师"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入项目名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="addressUserName">
        <el-input
          v-model="queryParams.addressUserName"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="addressTel">
        <el-input
          v-model="queryParams.addressTel"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否使用优惠券" prop="isUserCoupon">
        <el-select v-model="queryParams.isUserCoupon" placeholder="请选择是否使用优惠券" clearable>
          <el-option
            v-for="dict in dict.type.is_use_coupon"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付方式" prop="payType">
        <el-select v-model="queryParams.payType" placeholder="请选择支付方式" clearable>
          <el-option
            v-for="dict in dict.type.pay_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="下单时间">
        <el-date-picker
          v-model="daterangePlaceOrderTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="订单类型" prop="orderType">
        <el-select v-model="queryParams.orderType" placeholder="请选择订单类型" clearable>
          <el-option
            v-for="dict in dict.type.order_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus">
        <el-select v-model="queryParams.orderStatus" placeholder="请选择订单状态" clearable>
          <el-option
            v-for="dict in dict.type.order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否开通会员" prop="isOpenMembership">
        <el-select v-model="queryParams.isOpenMembership" placeholder="请选择是否开通会员" clearable>
          <el-option
            v-for="dict in dict.type.is_open_vip"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="订单是否异常" prop="isException">
        <el-select v-model="queryParams.isException" placeholder="请选择订单是否异常" clearable>
          <el-option
            v-for="dict in dict.type.is_exception"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['technicianUpgradeItemOrder:technicianUpgradeItemOrder:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['technicianUpgradeItemOrder:technicianUpgradeItemOrder:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['technicianUpgradeItemOrder:technicianUpgradeItemOrder:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['technicianUpgradeItemOrder:technicianUpgradeItemOrder:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="technicianUpgradeItemOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单ID" align="center" prop="id" />
      <el-table-column label="父订单号" align="center" prop="partnerOrderNo" />
      <el-table-column label="订单编号" align="center" prop="orderNo" />
      <el-table-column label="用户" align="center" prop="userId" />
      <el-table-column label="技师" align="center" prop="tid" />
      <el-table-column label="项目名" align="center" prop="itemName" />
      <el-table-column label="项目图" align="center" prop="itemPicture" />
      <el-table-column label="项目时长" align="center" prop="itemTime" />
      <el-table-column label="联系人" align="center" prop="addressUserName" />
      <el-table-column label="联系电话" align="center" prop="addressTel" />
      <el-table-column label="服务地点" align="center" prop="addressDetail" />
      <el-table-column label="服务时间" align="center" prop="serviceTime" />
      <el-table-column label="订单备注" align="center" prop="orderRemark" />
      <el-table-column label="支付金额" align="center" prop="needPayPrice" />
      <el-table-column label="订单总金额" align="center" prop="orderTotalPrice" />
      <el-table-column label="出行方式" align="center" prop="modeTravel" />
      <el-table-column label="项目价格" align="center" prop="orderItemPrice" />
      <el-table-column label="出行车费" align="center" prop="orderFarePrice" />
      <el-table-column label="总优惠金额" align="center" prop="discountPrice" />
      <el-table-column label="是否使用优惠券" align="center" prop="isUserCoupon">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.is_use_coupon" :value="scope.row.isUserCoupon"/>
        </template>
      </el-table-column>
      <el-table-column label="优惠券名" align="center" prop="userCouponId" />
      <el-table-column label="支付方式" align="center" prop="payType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pay_type" :value="scope.row.payType"/>
        </template>
      </el-table-column>
      <el-table-column label="下单时间" align="center" prop="placeOrderTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.placeOrderTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" prop="payTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="下单数量" align="center" prop="orderNum" />
      <el-table-column label="订单类型" align="center" prop="orderType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_type" :value="scope.row.orderType"/>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="orderStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_status" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="是否开通会员" align="center" prop="isOpenMembership">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.is_open_vip" :value="scope.row.isOpenMembership"/>
        </template>
      </el-table-column>
      <el-table-column label="会员名" align="center" prop="openMemberId" />
      <el-table-column label="会员开通金额" align="center" prop="openMemberPrice" />
      <el-table-column label="用户和技师之间的距离" align="center" prop="distance" />
      <el-table-column label="待接单等待时间" align="center" prop="takeOrderWaitTime" />
      <el-table-column label="技师出发位置" align="center" prop="leaveAddress" />
      <el-table-column label="接单时间" align="center" prop="takeOrderTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.takeOrderTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出发时间" align="center" prop="proceedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.proceedTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="到达位置" align="center" prop="arriveAddress" />
      <el-table-column label="到达照片" align="center" prop="arrivePicture" />
      <el-table-column label="到达备注" align="center" prop="arriveRemark" />
      <el-table-column label="到达时间" align="center" prop="arriveTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.arriveTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="服务开始时间" align="center" prop="startServiceTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startServiceTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="服务结束时间" align="center" prop="stopServiceTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.stopServiceTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际服务时长" align="center" prop="realServiceTime" />
      <el-table-column label="订单取消时间" align="center" prop="cancelTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cancelTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单取消原因" align="center" prop="cancelReason" />
      <el-table-column label="订单取消描述" align="center" prop="cancelDescribe" />
      <el-table-column label="预计收入" align="center" prop="expectIncome" />
      <el-table-column label="订单是否异常" align="center" prop="isException">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.is_exception" :value="scope.row.isException"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['technicianUpgradeItemOrder:technicianUpgradeItemOrder:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['technicianUpgradeItemOrder:technicianUpgradeItemOrder:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改升级订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTechnicianUpgradeItemOrder, getTechnicianUpgradeItemOrder, delTechnicianUpgradeItemOrder, addTechnicianUpgradeItemOrder, updateTechnicianUpgradeItemOrder } from "@/api/technicianUpgradeItemOrder/technicianUpgradeItemOrder";

export default {
  name: "TechnicianUpgradeItemOrder",
  dicts: ['is_use_coupon', 'pay_type', 'order_status', 'order_type', 'is_exception', 'is_open_vip'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 升级订单表格数据
      technicianUpgradeItemOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 创建时间时间范围
      daterangePlaceOrderTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        partnerOrderNo: null,
        orderNo: null,
        userId: null,
        tid: null,
        itemName: null,
        addressUserName: null,
        addressTel: null,
        isUserCoupon: null,
        payType: null,
        placeOrderTime: null,
        orderType: null,
        orderStatus: null,
        isOpenMembership: null,
        isException: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询升级订单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangePlaceOrderTime && '' != this.daterangePlaceOrderTime) {
        this.queryParams.params["beginPlaceOrderTime"] = this.daterangePlaceOrderTime[0];
        this.queryParams.params["endPlaceOrderTime"] = this.daterangePlaceOrderTime[1];
      }
      listTechnicianUpgradeItemOrder(this.queryParams).then(response => {
        this.technicianUpgradeItemOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        partnerOrderNo: null,
        orderNo: null,
        transactionId: null,
        userId: null,
        tid: null,
        itemId: null,
        itemSpecsId: null,
        itemName: null,
        itemPicture: null,
        itemTime: null,
        addressId: null,
        addressUserName: null,
        addressTel: null,
        addressDetail: null,
        serviceTime: null,
        orderRemark: null,
        needPayPrice: null,
        orderTotalPrice: null,
        modeTravel: null,
        orderItemPrice: null,
        orderFarePrice: null,
        discountPrice: null,
        isUserCoupon: null,
        userCouponId: null,
        payType: null,
        placeOrderTime: null,
        payTime: null,
        orderNum: null,
        orderType: null,
        orderStatus: null,
        isOpenMembership: null,
        openMemberId: null,
        openMemberPrice: null,
        distance: null,
        takeOrderWaitTime: null,
        startServiceWaitTime: null,
        serviceTotalTime: null,
        leaveAddress: null,
        takeOrderTime: null,
        proceedTime: null,
        arriveAddress: null,
        arrivePicture: null,
        arriveRemark: null,
        arriveTime: null,
        startServiceTime: null,
        stopServiceTime: null,
        realServiceTime: null,
        cancelTime: null,
        cancelReason: null,
        cancelDescribe: null,
        expectIncome: null,
        isException: null,
        isDelete: null,
        updateTime: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangePlaceOrderTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加升级订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTechnicianUpgradeItemOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改升级订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTechnicianUpgradeItemOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTechnicianUpgradeItemOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除升级订单编号为"' + ids + '"的数据项？').then(function() {
        return delTechnicianUpgradeItemOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('technicianUpgradeItemOrder/technicianUpgradeItemOrder/export', {
        ...this.queryParams
      }, `technicianUpgradeItemOrder_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
